package com.kaishengit.web;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kaishengit.entity.User;
import com.kaishengit.service.UserService;


public class LoginServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String name=request.getParameter("name");
		String password=request.getParameter("password");
		User user=new User();
		user.setName(name);
		user.setPassword(password);
		
		UserService us=new UserService();
		User loginUser=us.login(user);
		
		if(loginUser==null){
			response.sendRedirect("index.jspx?code=10001");
		}else{
			HttpSession session=request.getSession();
			session.setAttribute("curr_user", loginUser);
			response.sendRedirect("main.jspx");
		}
	}
}
